
				<div class="box span12">
					<div class="box-header" data-original-title>
						<h2><i class="halflings-icon white user"></i><span class="break"></span>分类列表</h2>
						<div class="box-icon">
							<a href="#" class="btn-setting"><i class="halflings-icon white wrench"></i></a>
							<a href="#" class="btn-minimize"><i class="halflings-icon white chevron-up"></i></a>
							<a href="#" class="btn-close"><i class="halflings-icon white remove"></i></a>
						</div>
					</div>
					<div class="box-content">
                        <div class="row-fluid">
                            <div class="span6">
                                <div id="DataTables_Table_0_length" class="dataTables_length">
                                    <label>
                                        <select size="1" id="sel_page" name="DataTables_Table_0_length" aria-controls="DataTables_Table_0">
                                            <option value="1">1</option>
                                            <option value="3">3</option>
                                            <option value="5">5</option>
                                            <option value="10" selected="selected">10</option>
                                        </select> 选择分页数
                                    </label>
                                </div>
                            </div>
                            <div class="span6">
                                <div class="dataTables_filter" id="DataTables_Table_0_filter">
                                    <label>搜索:
                                        <input type="text" aria-controls="DataTables_Table_0">
                                    </label>
                                </div>
                            </div>
                        </div>
						<table class="table table-striped table-bordered bootstrap-datatable datatable">
						  <thead>
							  <tr>
								  <th>id</th>
								  <th>名称</th>
								  <th>pid</th>
								  <th>详细</th>
							  </tr>
						  </thead>
						  <tbody>
                            <?php
                            if(!empty($cate)):
                            foreach($cate as $v) :
                            ?>
							<tr level="1" pid="<?php echo $v['pid']?>">
								<td><?php echo $v['id']?></td>
								<td filed="title" class="center db_edit">
                                <button id="<?php echo $v['id']?>" class="btn btn-success">+</button>
                                <?php echo $v['name']?>
                                </td>
								<td filed="content" class="center db_edit"><?php echo $v['pid']?></td>
								<td class="center">
									<a class="btn btn-info" href="index.php?c=cate&a=edit&admin=1&id=<?php echo $v['id']?>">
										<i class="halflings-icon white edit"></i>
									</a>
									<a class="btn btn-danger" onclick="return confirm('真的要删除？')" href="index.php?c=cate&a=del&admin=1&id=<?php echo $v['id']?>">
										<i class="halflings-icon white trash"></i>
									</a>
								</td>
							</tr>
                            <?php
                            endforeach;endif;
                            ?>
						  </tbody>
					  </table>
					</div>
				</div><!--/span-->
                <script src="resources/admin/js/jquery-1.9.1.min.js"></script>
                <script type="text/javascript">
                    $(function(){
                        $('.btn-danger').click(function(){
                            var url=$(this).attr('href');
                            $.ajax({
                                type: 'get',
                                url: url,

                                //dataType: 'json',
                                //data: {param1: 'value1'},
                                success:function(data){
                                    if(data>0)
                                    {
                                        if(confirm('下面有子集是否要删除？')){
                                            location.href=url;
                                        }

                                    }
                                    location.href=url;
                                }

                            })
                            return false;
                        })


                    })


                    $(function(){
                        $('tbody').on('click','.btn-success',function(){
                            var id=$(this).attr('id');
                            var obj=$(this);
                            //tr
                            var tr_obj=$(this).parent().parent();
                            //tr的pid
                            var tr_pid=tr_obj.attr('pid');
                           if($(this).text()=='+'){
                            //获取父级的level值
                            var level=parseInt(tr_obj.attr('level'));
                                left=level*40;
                                //点击加号时level递增
                                level++;
                                $(this).text('-');

                                $.ajax({
                                type: 'get',
                                url:"index.php?c=cate&a=edit&admin=1&id="+id ,

                                dataType: 'json',
                                //data: {param1: 'value1'},
                                success:function(data){
                                    var html='';
                                    for(i in data){
                                        html+='<tr level="'+level+'" pid="'+data[i].pid+'">';
                                            html+='<td>'+data[i].id+'</td>';
                                            html+='<td filed="title" class="center db_edit" style="padding-left:'+left+'px">';
                                            html+='<button id="'+data[i].id+'" class="btn btn-success">+</button>';
                                            html+=data[i].name;
                                            html+='</td>';
                                            html+='<td filed="content" class="center db_edit">'+data[i].pid+'</td>';
                                            html+='<td class="center">';
                                                html+='<a class="btn btn-info" href="index.php?c=cate&a=edit&admin=1&id='+data[i].id+'"><i class="halflings-icon white edit"></i></a>';
                                                html+='<a class="btn btn-danger" onclick="return confirm('+'真的要删除？'+')" href="index.php?c=cate&a=del&admin=1&id='+data[i].id+'">';
                                                    html+='<i class="halflings-icon white trash"></i>';
                                               html+='</a>';
                                            html+='</td>';
                                        html+='</tr>';
                                    }
                                    //在最后一条tr时候添加隐藏tr
                                        //if(i==data.length-1){
                                            html+='<tr pid="'+data[i].pid+'" style="display:none"></tr>';
                                        //}
                                    //在同级下面拼接html
                                    tr_obj.after(html);
                                }

                            })
                           }else{
                            $(this).text('+');
                            //根据pid移除tr
                            tr_obj.nextUntil('tr[pid='+tr_pid+']').remove();
                           }
                        })
                    })
                </script>

